import { TOKEN } from "@/common/const"
import storage from "./storage"
import { history } from "umi";




// 重定向到登录页处理登陆逻辑
export const goLogin = () => {
    storage.clear();
    if(history.location.pathname.includes ("/login")) return;
    const redirect = encodeURIComponent(window.location.pathname + window.location.search);
    history.push(`/login?redirect=${redirect}`);
}




export default async () => {
    const token = storage.get(TOKEN);
    const tokenRegisterTime = '1640995200000';
    const now = Date.now();
    const diff = now - parseInt(tokenRegisterTime, 10);
    // 不存在token或者超时
    // if (!token || !tokenRegisterTime || diff > 4 * 60 * 60 * 1000) return goLogin();
}

